#ifndef LEMC_BUTTON_H
#define LEMC_BUTTON_H

#include "WindowsIncludes.h"
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <string>
#include <functional>

#include "guielement.h"
#include "../resourcemanager/allegro_bitmap_manager.h"
#include "../system/global.h"

/*
* Provides the functionality of a simple button which can be pressed and on press triggers an action.
*/
class Button : public GuiElement
{
protected:
	// The graphic id of the graphic to show when the button is not pressed down.
	std::string m_graphic_up;

	// The graphic id of the graphic to show when the button is pressed down.
	std::string m_graphic_down;

	// The font of the label.
	ALLEGRO_FONT* m_label_font;

	// The color of the label.
	ALLEGRO_COLOR m_label_color;

	// The label text shown over the button graphic.
	std::string m_label;
	
	// True if the button is pressed down.
	bool m_down;

	// The action to be triggered when the button is pressed.
	std::function<void()> m_action;

public:
	/*
	* Creates the button.
	*
	* @param id The id of the button, should be unique.
	* @param x The x position of the upper left corner of the button.
	* @param y The y position of the upper left corner of the button.
	* @param size_x Horizontal size of the button.
	* @param size_y Vertical size of the button.
	* @param action The action to trigger when the button is pressed.
	* @param graphic_up The graphic to show when the button is not pressed.
	* @param graphic_down The graphic to show when the button is pressed.
	* @param label_font The label of the font to show. 
	* @param label The label to show on the button.
	* @param label_color The color of the label on the button.
	*/
	Button(std::string id, int x, int y, int size_x, int size_y, std::function<void()> action,
		std::string graphic_up = STANDARD_BUTTON_GRAPHIC_UP, std::string graphic_down = STANDARD_BUTTON_GRAPHIC_DOWN,
		ALLEGRO_FONT* label_font = NULL, std::string label = "", 
		const unsigned char label_color[3] = STANDARD_BUTTON_LABEL_COLOR);
	virtual ~Button();

	virtual void PrimaryMouseButtonUp(int x, int y);
	virtual void PrimaryMouseButtonDown(int x, int y);

	virtual void Draw();
};

#endif